package qc.module.duty.api.controller;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;
import qc.common.core.constants.QCAuthConstant;
import qc.common.core.enums.TimeRangeLengthEnum;
import qc.common.core.exception.QCPromptException;
import qc.common.core.table.QCTable;
import qc.common.core.table.QCTableCell;
import qc.common.core.table.QCTableRow;
import qc.common.core.utils.DateUtil;
import qc.module.duty.dto.display.DutyDisplayDayScheduleDto;
import qc.module.duty.dto.display.DutyDisplayQueryConditionDto;
import qc.module.duty.dto.display.DutyDisplayQueryResultCalendarDto;
import qc.module.duty.dto.display.DutyResultDto;
import qc.module.duty.dto.group.DutyGroupDto;
import qc.module.duty.dto.schedule.DutyScheduleItemDto;
import qc.module.duty.dto.schedule.DutyScheduleShiftMemberDto;
import qc.module.duty.dto.staff.DutyStaffDto;
import qc.module.duty.entity.DutySchedule;
import qc.module.duty.service.*;
import qc.module.platform.dto.dept.DeptSimpleDto;

import javax.servlet.http.HttpServletRequest;
import java.util.*;
import java.util.stream.Collectors;

/**
 * 值班表展示Controller
 *
 * @author QuCheng Tech
 * @since 2023/8/9
 */
@RestController
@RequestMapping("/display")
public class DutyController {
    @Autowired
    private RestTemplate restTemplate;

    @Autowired
    private DiscoveryClient discoveryClient;

    @Autowired
    HttpServletRequest request;

    private DutyDisplayService service;

    @Autowired
    public void setDutyDisplayService(DutyDisplayService service) {
        this.service = service;
    }

    private DutyScheduleService dutyScheduleService;

    @Autowired
    private void setDutyScheduleService(DutyScheduleService dutyScheduleService) {
        this.dutyScheduleService = dutyScheduleService;
    }

    private DutyStaffService dutyStaffService;

    @Autowired
    public void setDutyStaffService(DutyStaffService dutyStaffService) {
        this.dutyStaffService = dutyStaffService;
    }

    private DutyScheduleMemberService dutyScheduleMemberService;

    @Autowired
    public void setDutyScheduleMemberService(DutyScheduleMemberService dutyScheduleMemberService) {
        this.dutyScheduleMemberService = dutyScheduleMemberService;
    }

    private DutyGroupService dutyGroupService;

    @Autowired
    public void setDutyGroupService(DutyGroupService dutyGroupService) {
        this.dutyGroupService = dutyGroupService;
    }

    /***
     * 查询日历结果值班表
     *
     * @param condition 查询值班信息的条件
     * @return qc.module.duty.dto.display.DutyDisplayQueryResultCalendarDto
     * @author QuCheng Tech
     * @since 2023/8/9
     */
    @RequestMapping(value = "/calendar", method = {RequestMethod.POST, RequestMethod.GET})
    public DutyDisplayQueryResultCalendarDto queryDutyCalendar(@RequestBody DutyDisplayQueryConditionDto condition) throws QCPromptException {
        if (condition == null)
            throw new QCPromptException("值班表条件不能为空");
        if (StringUtils.isBlank(condition.getDate()))
            throw new QCPromptException("值班表条件中的日期不能为空");

        TimeRangeLengthEnum timeRangeLengthEnum = getTimeRangeLengthEnum(condition.getTmtype());

        Date date = null;
        if (StringUtils.isNotBlank(condition.getDate())) {
            try {
                date = DateUtil.parseDate(condition.getDate());
            } catch (Exception e) {
                // 时间转换错误，抛出自定义异常
                throw new QCPromptException("值班表条件中的日期转换错误");
            }
        }

        DutyDisplayQueryResultCalendarDto result = new DutyDisplayQueryResultCalendarDto();

        Date beginTime = date;
        Date endTime = date;
        if (timeRangeLengthEnum == TimeRangeLengthEnum.MONTH) {
            endTime = DateUtil.addDays(DateUtil.addMonths(beginTime, 0x1), -1);
        } else if (timeRangeLengthEnum == TimeRangeLengthEnum.QUARTER) {
            endTime = DateUtil.addDays(DateUtil.addMonths(beginTime, 0x1), -1);
        } else {
            //默认按年显示
            endTime = DateUtil.addDays(DateUtil.addYears(beginTime, 0x1), -1);
        }

        return generateTestCalendarData(beginTime, endTime, condition.getDeptids());
    }

    //生成测试数据
    DutyDisplayQueryResultCalendarDto generateTestCalendarData(Date beginTime, Date endTime, int[] deptids) {
        DutyDisplayQueryResultCalendarDto result = new DutyDisplayQueryResultCalendarDto();

        List<Date> dates = new ArrayList<>();
        //遍历起止日期得到所有的日期
        Date date = beginTime;
        while (date.before(endTime)) {
            dates.add(date);

            date = DateUtil.addDays(date, 0x1);
        }
        //result.setDates(dates.stream().map(p -> DateUtil.getDateString(p)).collect(Collectors.toList()));

        List<DutyGroupDto> groups = new ArrayList<>();
        //遍历所有部门--值班分组，生成分组信息
        for (int i = 0; i < deptids.length; i++) {
            DutyGroupDto groupDto = new DutyGroupDto();

            groupDto.setDeptid(deptids[i]);
            if (i == 0x0)
                groupDto.setName("生产组");
            else if (i == 0x1)
                groupDto.setName("信息组");
            else if (i == 0x1)
                groupDto.setName("库房组");
            else if (i == 0x2)
                groupDto.setName("运维部");
            else if (i == 0x3)
                groupDto.setName("保安组");
            else
                groupDto.setName("分组" + i);

            groups.add(groupDto);
        }
        result.setGroups(groups);

        List<DutyDisplayDayScheduleDto> schedules = new ArrayList<>();
        //生成值班表信息，遍历日期、遍历值班分组
        for (Date day : dates) {
            DutyDisplayDayScheduleDto daySchedule = new DutyDisplayDayScheduleDto();
            daySchedule.setDate(DateUtil.getDateString(day));
            daySchedule.setHoliday(false);
            daySchedule.setTmtext("");

            List<DutyScheduleItemDto> dayScheduleItems = new ArrayList<>();
            for (int i = 0; i < deptids.length; i++) {
                //当天，每个值班分组的值班信息
                DutyScheduleItemDto item = new DutyScheduleItemDto();

                //item.setBegintm(DateUtil.getDateString(day));
                //item.setEndtm(DateUtil.getDateString(day));
                item.setGroupid(i);
                //item.setGroupname("值班分组名称" + i);

                //item.setMembers("张  三 13912345678 123456" + i + "<br />李  四 13912345678 123456" + i);
                item.setMembers("张  三 13912345678 123456" + i);

                dayScheduleItems.add(item);
            }
            daySchedule.items = dayScheduleItems;
            schedules.add(daySchedule);
        }
        result.setSchedules(schedules);

        return result;
    }

    /***
     * 查询表格结果值班表
     *
     * @param condition 查询值班信息的条件
     * @return qc.module.duty.dto.display.DutyDisplayQueryResultTableRowDto
     * @author QuCheng Tech
     * @since 2023/8/10
     */
    @RequestMapping(value = "/table", method = {RequestMethod.POST, RequestMethod.GET})
    public QCTable queryDutyTable(@RequestBody DutyDisplayQueryConditionDto condition) throws QCPromptException {
        if (condition == null)
            throw new QCPromptException("值班表条件不能为空");
        if (StringUtils.isBlank(condition.getDate()))
            throw new QCPromptException("值班表条件中的日期不能为空");

        TimeRangeLengthEnum timeRangeLengthEnum = getTimeRangeLengthEnum(condition.getTmtype());

        Date date = null;
        if (StringUtils.isNotBlank(condition.getDate())) {
            try {
                date = DateUtil.parseDate(condition.getDate());
            } catch (Exception e) {
                // 时间转换错误，抛出自定义异常
                throw new QCPromptException("值班表条件中的日期转换错误");
            }
        }

        // 调用 platform 微服务获取有效的部门/组织信息
        List<DeptSimpleDto> projectDepts = getDefaultProjectValidDepts();
        //根据查询条件中插入的部门ID进行过滤
        List<DeptSimpleDto> queryConditionDepts = null;

        //测试数据
        //return generateTestTableData(beginTime, endTime, condition.getDeptids());
        return service.queryDutyDisplayTable(timeRangeLengthEnum, date, condition.getDeptids(), getDeptIdAndNames(projectDepts));
    }

    /***
     * 获取选择的时段类型枚举，默认为月
     *
     * @param tmtype 输入的时段类型值
     * @return qc.common.core.enums.TimeRangeLengthEnum
     * @author QuCheng Tech
     * @since 2023/8/14
     */
    TimeRangeLengthEnum getTimeRangeLengthEnum(int tmtype) {
        if (tmtype >= 0x0) {
            for (TimeRangeLengthEnum item : TimeRangeLengthEnum.values()) {
                if (item.getIndex() == tmtype) {//判断序号使用getIndex，判断内容使用getName
                    return item;
                }
            }
        }

        return TimeRangeLengthEnum.MONTH;
    }

    //生成测试数据
    QCTable generateTestTableData(Date beginTime, Date endTime, int[] deptids) {
        QCTable result = new QCTable();
        String beginDateString = DateUtil.getDateString(beginTime);
        String endDateString = DateUtil.getDateString(endTime);
        //result.setBegintm(beginDateString);
        //result.setEndtm(endDateString);
        //result.setTitle("生技部" + beginDateString + "-" + endDateString + "值班安排");

        List<Date> dates = new ArrayList<>();
        //遍历起止日期得到所有的日期
        Date date = beginTime;
        while (date.before(endTime)) {
            dates.add(date);

            //date = DateUtil.addDays(date, 0x1);
            int d = DateUtil.getDay(date);
            if (d % 8 == 0) {
                //测试将一周分为2段
                dates.add(DateUtil.addDays(date, 0x3));
            }
            date = DateUtil.addDays(date, 0x7);
        }
        //result.setDates(dates.stream().map(p -> DateUtil.getDateString(p)).collect(Collectors.toList()));

        int groupCol = 0x0;
        List<DutyGroupDto> groups = new ArrayList<>();
        //遍历所有部门--值班分组，生成分组信息
        for (int i = 0; i < deptids.length; i++) {
            DutyGroupDto groupDto = new DutyGroupDto();

            groupDto.setDeptid(deptids[i]);
            if (i == 0x0)
                groupDto.setName("生产组");
            else if (i == 0x1)
                groupDto.setName("信息组");
            else if (i == 0x1)
                groupDto.setName("库房组");
            else if (i == 0x2)
                groupDto.setName("运维部");
            else if (i == 0x3)
                groupDto.setName("保安组");
            else
                groupDto.setName("分组" + i);

            //模拟技术的部门列宽为2
            if (i % 2 == 1)
                groupDto.setCol(0x2);
            else
                groupDto.setCol(0x1);

            groupCol += groupDto.getCol();

            groups.add(groupDto);
        }
        //result.setGroups(groups);

        //生成表头行
        List<QCTableRow> heads = new ArrayList<>();
        //标题行
        QCTableRow headerTitleRow = new QCTableRow();
        List<QCTableCell> cells = new ArrayList<>();
        QCTableCell cell = new QCTableCell();
        cell.setRowspan(0x1);
        cell.setColspan(groupCol * 3 + 2);
        cell.setText("生技部" + beginDateString + "-" + endDateString + "值班安排");
        cells.add(cell);
        headerTitleRow.setCells(cells);
        heads.add(headerTitleRow);
        //分组行
        QCTableRow headerGroupRow = new QCTableRow();
        //成员行
        QCTableRow headerMemberRow = new QCTableRow();
        List<QCTableCell> groupCells = new ArrayList<>();
        List<QCTableCell> memberCells = new ArrayList<>();
        cell = new QCTableCell();
        cell.setRowspan(0x2);
        cell.setColspan(0x1);
        cell.setText("日期");
        groupCells.add(cell);
        cell = new QCTableCell();
        cell.setRowspan(0x2);
        cell.setColspan(0x1);
        cell.setText("星期");
        groupCells.add(cell);
        for (DutyGroupDto group : groups) {
            groupCol = group.getCol();
            //分组行
            cell = new QCTableCell();
            cell.setRowspan(0x1);
            cell.setColspan(0x3 * groupCol);
            cell.setText(group.getName());
            if (group.getName().equalsIgnoreCase("生产组"))
                cell.setStyle("background-color: pink;");
            else if (group.getName().equalsIgnoreCase("信息组"))
                cell.setStyle("background-color: yellow;");
            else if (group.getName().equalsIgnoreCase("库房组"))
                cell.setStyle("background-color: cyan;");
            else if (group.getName().equalsIgnoreCase("运维部"))
                cell.setStyle("background-color: green;");
            else if (group.getName().equalsIgnoreCase("保安组"))
                cell.setStyle("background-color: purple;");
            groupCells.add(cell);
            //成员行
            for (int i = 1; i <= groupCol; i++) {
                QCTableCell memberCell = new QCTableCell();
                memberCell.setRowspan(0x1);
                memberCell.setColspan(0x1);
                memberCell.setText("姓名");
                memberCells.add(memberCell);

                memberCell = new QCTableCell();
                memberCell.setRowspan(0x1);
                memberCell.setColspan(0x1);
                memberCell.setText("手机号");
                memberCells.add(memberCell);

                memberCell = new QCTableCell();
                memberCell.setRowspan(0x1);
                memberCell.setColspan(0x1);
                memberCell.setText("短号");
                memberCells.add(memberCell);
            }
        }
        headerGroupRow.setCells(groupCells);
        headerMemberRow.setCells(memberCells);
        heads.add(headerGroupRow);
        heads.add(headerMemberRow);
        result.setHeaderRows(heads);

        List<QCTableRow> bodys = new ArrayList<>();
        //生成值班表信息，遍历日期、遍历值班分组
        for (Date day : dates) {
            int d = DateUtil.getDay(day);

            QCTableRow row = new QCTableRow();
            cells = new ArrayList<>();

            //模拟将1周分为2段，为2个班次
            if (d % 8 == 0 || d % 11 == 0) {
                cell = new QCTableCell();
                cell.setRowspan(0x1);
                cell.setColspan(0x1);
                if (d % 8 == 0)
                    cell.setText(d + "~" + (d + 3));
                else
                    cell.setText(d + "~" + (d + 4));
                cells.add(cell);

                cell = new QCTableCell();
                cell.setRowspan(0x1);
                cell.setColspan(0x1);
                cell.setText("节假日");
                cells.add(cell);
            } else {
                cell = new QCTableCell();
                cell.setRowspan(0x1);
                cell.setColspan(0x1);
                cell.setText(d + "~" + (d + 7));
                cells.add(cell);

                cell = new QCTableCell();
                cell.setRowspan(0x1);
                cell.setColspan(0x1);
                cell.setText("第N周");
                cells.add(cell);
            }
            for (DutyGroupDto group : groups) {
                groupCol = group.getCol();
                //成员信息
                for (int i = 1; i <= groupCol; i++) {
                    cell = new QCTableCell();
                    cell.setRowspan(0x1);
                    cell.setColspan(0x1);
                    cell.setText("姓名" + i);
                    if (group.getName().equalsIgnoreCase("生产组"))
                        cell.setStyle("background-color: pink;");
                    else if (group.getName().equalsIgnoreCase("信息组"))
                        cell.setStyle("background-color: yellow;");
                    else if (group.getName().equalsIgnoreCase("库房组"))
                        cell.setStyle("background-color: cyan;");
                    else if (group.getName().equalsIgnoreCase("运维部"))
                        cell.setStyle("background-color: green;");
                    else if (group.getName().equalsIgnoreCase("保安组"))
                        cell.setStyle("background-color: purple;");
                    cells.add(cell);

                    cell = new QCTableCell();
                    cell.setRowspan(0x1);
                    cell.setColspan(0x1);
                    cell.setText("1388888888" + i);
                    if (group.getName().equalsIgnoreCase("生产组"))
                        cell.setStyle("background-color: pink;");
                    else if (group.getName().equalsIgnoreCase("信息组"))
                        cell.setStyle("background-color: yellow;");
                    else if (group.getName().equalsIgnoreCase("库房组"))
                        cell.setStyle("background-color: cyan;");
                    else if (group.getName().equalsIgnoreCase("运维部"))
                        cell.setStyle("background-color: green;");
                    else if (group.getName().equalsIgnoreCase("保安组"))
                        cell.setStyle("background-color: purple;");
                    cells.add(cell);

                    cell = new QCTableCell();
                    cell.setRowspan(0x1);
                    cell.setColspan(0x1);
                    cell.setText("68000" + i);
                    if (group.getName().equalsIgnoreCase("生产组"))
                        cell.setStyle("background-color: pink;");
                    else if (group.getName().equalsIgnoreCase("信息组"))
                        cell.setStyle("background-color: yellow;");
                    else if (group.getName().equalsIgnoreCase("库房组"))
                        cell.setStyle("background-color: cyan;");
                    else if (group.getName().equalsIgnoreCase("运维部"))
                        cell.setStyle("background-color: green;");
                    else if (group.getName().equalsIgnoreCase("保安组"))
                        cell.setStyle("background-color: purple;");
                    cells.add(cell);
                }
            }
            row.setCells(cells);
            bodys.add(row);

            if (d % 15 == 0) {
                //模拟一个班次有多行数据
                //先添加当前行，再生成一个新行，新行中不需要时间信息
                row = new QCTableRow();
                cells = new ArrayList<>();
                //日期和星期列不需要信息
                cell = new QCTableCell();
                cell.setRowspan(0x1);
                cell.setColspan(0x1);
                cell.setText(null);
                cells.add(cell);

                cell = new QCTableCell();
                cell.setRowspan(0x1);
                cell.setColspan(0x1);
                cells.add(cell);

                for (int i = 0; i < deptids.length; i++) {
                    groupCol = groups.get(i).getCol();
                    if (i < 0x2) {
                        for (int j = 1; j <= groupCol; j++) {
                            cell = new QCTableCell();
                            cell.setRowspan(0x1);
                            cell.setColspan(0x1);
                            cell.setText("姓名" + j);
                            cells.add(cell);

                            cell = new QCTableCell();
                            cell.setRowspan(0x1);
                            cell.setColspan(0x1);
                            cell.setText("1388888888" + j);
                            cells.add(cell);

                            cell = new QCTableCell();
                            cell.setRowspan(0x1);
                            cell.setColspan(0x1);
                            cell.setText("68000" + j);
                            cells.add(cell);
                        }
                    } else {
                        for (int j = 1; j <= groupCol; j++) {
                            cell = new QCTableCell();
                            cell.setRowspan(0x1);
                            cell.setColspan(0x1);
                            cell.setText(null);
                            cells.add(cell);

                            cell = new QCTableCell();
                            cell.setRowspan(0x1);
                            cell.setColspan(0x1);
                            cell.setText(null);
                            cells.add(cell);

                            cell = new QCTableCell();
                            cell.setRowspan(0x1);
                            cell.setColspan(0x1);
                            cell.setText(null);
                            cells.add(cell);
                        }
                    }
                }
                row.setCells(cells);

                bodys.add(row);
            }
        }
        result.setBodyRows(bodys);

        return result;
    }

    /***
     * 根据部门信息集合得到部门ID和名称对应关系
     *
     * @param depts 部门信息集合
     * @return java.util.Map<java.lang.Integer, java.lang.String>
     * @author QuCheng Tech
     * @since 2023/8/11
     */
    Map<Integer, String> getDeptIdAndNames(List<DeptSimpleDto> depts) {
        if (depts != null && depts.size() > 0x0) {
            Map<Integer, String> result = new HashMap<>();
            for (DeptSimpleDto dept : depts) {
                result.put(dept.getId(), dept.getName());
            }
            return result;
        }

        return null;
    }

    /***
     * 获取默认项目的有效部门列表，用于在值班表查询中显示部门名称
     *
     * @return java.util.List<qc.module.platform.dto.dept.DeptSimpleDto>
     * @author QuCheng Tech
     * @since 2023/8/14
     */
    List<DeptSimpleDto> getDefaultProjectValidDepts() {
        ServiceInstance service = discoveryClient.getInstances("module-platform").get(0);
        String url = "http://" + service.getHost() + ":" + service.getPort() + "/dept/valid";

        HttpEntity<String> formEntity = new HttpEntity<String>(null, null);
        ParameterizedTypeReference<List<DeptSimpleDto>> responseType = new ParameterizedTypeReference<List<DeptSimpleDto>>() {
        };

        ResponseEntity<List<DeptSimpleDto>> response = restTemplate.exchange(
                url,//获取资源的地址
                HttpMethod.GET,
                formEntity,
                responseType
        );
        List<DeptSimpleDto> resultDto = response.getBody();
        return resultDto;
    }

    /**
     * 根据token获取用户所在项目中所有有效的部门
     *
     * @param token 用户登录得到的Token
     * @return 部门简要信息集合
     * @author QuCheng Tech
     * @since 2023/5/31
     */
    List<DeptSimpleDto> getProjectValidDepts(String token) {
        HttpHeaders headers = new HttpHeaders();
        headers.add(QCAuthConstant.TOKEN_HEADER_KEY, token);

        ServiceInstance service = discoveryClient.getInstances("module-platform").get(0);
        String url = "http://" + service.getHost() + ":" + service.getPort() + "/dept/projectvalid";

        HttpEntity<String> formEntity = new HttpEntity<String>(null, headers);
        ParameterizedTypeReference<List<DeptSimpleDto>> responseType = new ParameterizedTypeReference<List<DeptSimpleDto>>() {
        };

        ResponseEntity<List<DeptSimpleDto>> response = restTemplate.exchange(
                url,//获取资源的地址
                HttpMethod.GET,
                formEntity,
                responseType
        );
        List<DeptSimpleDto> resultDto = response.getBody();
        return resultDto;
    }

    /**
     * 获取指定值班分组ID的值班成员集合
     *
     * @param id 值班分组ID
     * @return java.util.List<qc.module.duty.dto.staff.DutyStaffDto>
     * @author QuCheng Tech
     * @since 2023/12/26
     */
    @RequestMapping(value = "/groupmembers", method = {RequestMethod.GET})
    public DutyResultDto getGroupMembersByParam(@RequestParam(value = "id", required = true) String id) {
        return getMembersByDutyGroupId(id, DateUtil.getNowDate());
    }

    /**
     * 获取指定值班分组ID的值班成员集合
     *
     * @param id 值班分组ID
     * @return java.util.List<qc.module.duty.dto.staff.DutyStaffDto>
     * @author QuCheng Tech
     * @since 2023/12/26
     */
    @RequestMapping(value = "/groupmembers/{id}", method = {RequestMethod.GET})
    public DutyResultDto getGroupMembersByPath(@PathVariable(required = true) String id) {
        return getMembersByDutyGroupId(id, DateUtil.getNowDate());
    }

    DutyResultDto getMembersByDutyGroupId(String groupId, Date date) {
        DutyResultDto result = new DutyResultDto();

        if (date != null) {
            result.setTm(DateUtil.getDateTimeString(date));

            //如果指定的分组ID为空或错误，不进行错误提示，返回空结果
            if (!StringUtils.isBlank(groupId)) {
                try {
                    Integer gid = Integer.parseInt(groupId);
                    //获取值班分组信息
                    DutyGroupDto group = dutyGroupService.get(gid);
                    result.setGroup(group);

                    List<Integer> filterGroupIds = new ArrayList<>();
                    filterGroupIds.add(gid);

                    //根据值班分组ID查询排班表信息
                    List<DutySchedule> schedules = dutyScheduleService.querySchedules(date, date, filterGroupIds);
                    if (schedules != null && schedules.size() > 0x0) {
                        //获取排班id，如果有多个获取第1个
                        Integer scheduleId = schedules.get(0x0).getId();
                        //根据排班id获取值班人员信息--id集合
                        List<DutyScheduleShiftMemberDto> scheduleShiftMemberDtos = dutyScheduleMemberService.getTeamMembers(scheduleId);
                        if (scheduleShiftMemberDtos != null && scheduleShiftMemberDtos.size() > 0x0) {
                            //查询值班人员信息
                            List<DutyStaffDto> allDutyStaffs = dutyStaffService.getAllStaffs();
                            if (allDutyStaffs != null && allDutyStaffs.size() > 0x0) {
                                List<DutyStaffDto> resultStaffs = new ArrayList<>();

                                for (DutyScheduleShiftMemberDto scheduleShiftMemberDto : scheduleShiftMemberDtos) {
                                    int memberId = scheduleShiftMemberDto.getMemberid();
                                    //从所有人员信息中根据id获取人员信息
                                    List<DutyStaffDto> staffDtos = allDutyStaffs.stream().filter(p -> p.getId() == memberId).collect(Collectors.toList());
                                    if (staffDtos != null && staffDtos.size() > 0x0) {
                                        resultStaffs.add(staffDtos.get(0x0));
                                    }
                                }

                                result.setMembers(resultStaffs);
                            }
                        }
                    }
                } catch (NumberFormatException ex) {

                }
            }
        }

        return result;
    }
}
